{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{if !empty($data)}修改{else}添加{/if}</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add_cate" id="add_robot" method="post" action="">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">规则名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" value="{$data.name|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">规则类型：</label>
                            <div class="col-sm-4 m-l-n">
                                <select class="form-control" name="type" id="type">
                                    <option  value="">请选择</option>
                                    <option {if condition="@$data.type eq 1"}selected{/if} value="1">低</option>
                                    <option {if condition="@$data.type eq 2"}selected{/if} value="2">中</option>
                                    <option {if condition="@$data.type eq 3"}selected{/if} value="3">高</option>
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">答题秒数：</label>
                            <div class="col-sm-4 m-l-n">
                                <select class="form-control" name="seconds" id="seconds">
                                    <option  value="">请选择</option>
                                    <option {if condition="@$data.seconds eq 1"}selected{/if} value="1">1</option>
                                    <option {if condition="@$data.seconds eq 2"}selected{/if} value="2">2</option>
                                    <option {if condition="@$data.seconds eq 3"}selected{/if} value="3">3</option>
                                    <option {if condition="@$data.seconds eq 4"}selected{/if} value="4">4</option>
                                    <option {if condition="@$data.seconds eq 5"}selected{/if} value="5">5</option>
                                    <option {if condition="@$data.seconds eq 6"}selected{/if} value="6">6</option>
                                    <option {if condition="@$data.seconds eq 7"}selected{/if} value="7">7</option>
                                    <option {if condition="@$data.seconds eq 8"}selected{/if} value="8">8</option>
                                    <option {if condition="@$data.seconds eq 9"}selected{/if} value="9">9</option>
                                    <option {if condition="@$data.seconds eq 10"}selected{/if} value="10">10</option>
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">答题准确率&nbsp%：</label>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">第一题：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_right_rate1" type="text" class="form-control" name="answer_right_rate1" value="{$data.answer_right_rate1|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">第二题：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_right_rate2" type="text" class="form-control" name="answer_right_rate2" value="{$data.answer_right_rate2|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">第三题：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_right_rate3" type="text" class="form-control" name="answer_right_rate3" value="{$data.answer_right_rate3|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">第四题：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_right_rate4" type="text" class="form-control" name="answer_right_rate4" value="{$data.answer_right_rate4|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">第五题：</label>
                            <div class="input-group col-sm-4">
                                <input id="answer_right_rate5" type="text" class="form-control" name="answer_right_rate5" value="{$data.answer_right_rate5|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3">
                        <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                        <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                    </div>
                </div>
                </form>
            </div>
        </div>

    </div>
</div>
</div>
{include file="public/footer" /}

<script type="text/javascript">

    $(function(){

        //初始化上传图片插件
        initUploadImg();
    });

    function uploadImgCallback(name,id,src){

        $('#cover_id_p_cover').val(src);
    }

    $(function(){
        $('#add_robot').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#name').val())){
                layer.msg('请输入规则名称',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            else if( '' == $.trim($('#type').val())){
                layer.msg('请选择规则类型',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }else if( '' == $.trim($('#seconds').val())){
                    layer.msg('请选择答题时间',{icon:2,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
            }
            else if( '' == $.trim($('#answer_right_rate1').val())){
                layer.msg('请输入第一题准确率',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            else if( '' == $.trim($('#answer_right_rate2').val())){
                layer.msg('请输入第二题准确率',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            else if( '' == $.trim($('#answer_right_rate3').val())){
                layer.msg('请输入第三题准确率',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            else if( '' == $.trim($('#answer_right_rate4').val())){
                layer.msg('请输入第四题准确率',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            else if( '' == $.trim($('#answer_right_rate5').val())){
                layer.msg('请输入第五题准确率',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('robot/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }
        }

    });
</script>

<script type="text/javascript">

</script>
</body>
</html>